package com.zhang.gateway.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @Description
 * @Author zsw
 * @Date 2019/11/5 13:49
 * @Version V1.0
 **/
@Configuration
@ConfigurationProperties(prefix = "validate-code.property")
@Data
public class ValidateCodeConfiguration {
    private String k1;
    private String k2;
    private String k3;
    private String k4;
    private String k5;
    private String k6;
    private String k7;
    private String v1;
    private String v2;
    private String v3;
    private String v4;
    private String v5;
    private String v6;
    private String v7;


    @Bean
    public DefaultKaptcha producer() {

        Properties properties = new Properties();
        properties.put(k1, v1.equalsIgnoreCase("true")||v1.equalsIgnoreCase("yes")?"yes":"no");
        properties.put(k2, v2);
        properties.put(k3, v3);
        properties.put(k4, v4);
        properties.put(k5, v5);
        properties.put(k6, v6);
        properties.put(k7, v7);
        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}